package com.xxc.exam.entity.vo

import com.xxc.common.anotation.POKO
import com.xxc.exam.entity.QuestionEntity
import com.xxc.exam.entity.pojo.Question
import org.springframework.beans.BeanUtils
import java.io.Serializable
import java.math.BigInteger
import java.sql.Timestamp
import javax.persistence.*

@POKO
data class QuestionVO (var id: BigInteger? = null,
                       var type:Int? = null,
                       var content:String? = null,
                       var level:Int? = null,
                       var options:String? = null,
                       var answer:String? = null,
                       var analysis:String? = null,
                       var category: CategoryVO? = null,
                       var created: Timestamp? = null,
                       var creator: ManagerVO? = null) : Serializable
{
    companion object{

        fun map(entity:QuestionEntity): QuestionVO {
            return QuestionVO(entity.id,entity.type,entity.title,entity.level,entity.options,entity.answer,
                    entity.analysis, CategoryVO(id = entity.category?.id,name = entity.category?.name),entity.gmtCreate,
                    ManagerVO(entity.creator?.id,entity.creator?.email))
        }
        
        fun map(question:Question):QuestionVO
        {
            val questionVO = QuestionVO(content = question.title,created = question.gmtCreate)
            BeanUtils.copyProperties(question,questionVO)
            return questionVO
        }
    }
}